#include <iostream>

 

using namespace std;

int arrayMaxSum(int* arr, int n)

{
int sum = arr[0];

int tmp = 0;

 

for(int i=0; i<n; i++)

    {
if(tmp< 0)

tmp = arr[i];

else

tmp += arr[i];

if (sum <tmp)

sum = tmp;


    }

return sum;

}

int main()

{
int myArr[100] = {1, -2, 3, 5, -1};

int num = 5;

int rlt = arrayMaxSum(myArr, num);

cout<<rlt;

return 0;

}
